package conf

import (
	"andals/gobox/misc"
	"encoding/json"
	//     "fmt"
	"io/ioutil"
)

type Cconf struct {
	ContainerName string `json:"container_name"`
	ExecPath      string `json:"exec_path"`
}

var dconf map[string]*Cconf

func Init(dconfPath string) {
	if !misc.FileExist(dconfPath) {
		panic(dconfPath + " not exists")
	}

	jsonStr, _ := ioutil.ReadFile(dconfPath)
	err := json.Unmarshal(jsonStr, &dconf)
	if nil != err {
		panic("parse dconf error")
	}
}

func GetAllContainerConf() map[string]*Cconf {
	return dconf
}

func GetContainerConf(key string) *Cconf {
	cconf, ok := dconf[key]
	if !ok {
		panic(key + "not exist in dconf")
	}

	return cconf
}
